package com.zoke.daycarpool.parser;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.zoke.daycarpool.domain.DayCarpool;

public class MainParser extends BaseCarParser<List<DayCarpool>> {

	@Override
	public List<DayCarpool> parseJson(String json) throws JSONException {
		JSONObject jo = getJsonObject(json);
		List<DayCarpool> list = new ArrayList<DayCarpool>();
		JSONArray array = jo.getJSONArray("result");
		for (int x = 0; x < array.length(); x++) {
			DayCarpool dc = new DayCarpool();
			JSONObject joo = array.getJSONObject(x);
			dc.setMsgId(joo.optLong("msgId"));
			dc.setDest(joo.optString("dest"));
			dc.setDist(joo.optString("dist"));
			dc.setMobile(joo.optString("mobile"));
			dc.setNum(joo.optInt("num"));
			dc.setPhoto(joo.optString("photo"));
			dc.setPrice(joo.optInt("price"));
			dc.setPubTime(joo.optLong("pubTime"));
			dc.setRemark(joo.optString("remark"));
			dc.setStart(joo.optString("start"));
			dc.setStartLit(joo.optString("startLit"));
			dc.setStartTime(joo.optLong("startTime"));
			dc.setTarget(joo.optInt("target"));
			dc.setName(joo.optString("name"));
			list.add(dc);
		}
		return list;
	}

}
